x86: adjust rdtsc inline assembly
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 18 Feb 2015 16:02:18 +0000 (17:02 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 18 Feb 2015 16:02:18 +0000 (17:02 +0100)
commit28309debeb31815053eca5ec8b8f37228314911a
tree2f755e1ffb4cf7a5b19a5a815ddc2cd4feb5af72
parenta7d6ba754d39d3e71963b2224f91541dd5289946
x86: adjust rdtsc inline assembly

Currently there are three related rdtsc macros, all of which are lowercase and
not obviously macros, which write by value to their parameters.

This is non-intuitive to program which, being contrary to C semantics for code
appearing to be a regular function call.  It is also causes Coverity to
conclude that __udelay() has an infinite loop, as all of its loop conditions
are constant.

Two of these macros (rdtsc() and rdtscl()) have only a handful of uses while
the vast majority of code uses the rdtscll() variant.  rdtsc() and rdtscll()
are equivalent, while rdtscl() discards the high word.

Replace all 3 macros with a static inline which returns the complete tsc.

Most of this patch is a mechanical change of

  - rdtscll($FOO);
  + $FOO = rdtsc();

And a diff of the generated assembly confirms that this is no change at all.

The single use of the old rdtsc() in emulate_privileged_op() is altered to use
the new rdtsc() and the rdmsr_writeback path to set eax/edx appropriately.

The pair of use of rdtscl() in __udelay() are extended to use full 64bit
values, which makes the overflow edge condition (and early exit from the loop)
far rarer.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
12 files changed:
xen/arch/x86/apic.c
xen/arch/x86/cpu/mcheck/mce.c
xen/arch/x86/delay.c
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/save.c
xen/arch/x86/hvm/svm/svm.c
xen/arch/x86/platform_hypercall.c
xen/arch/x86/smpboot.c
xen/arch/x86/time.c
xen/arch/x86/traps.c
xen/include/asm-x86/msr.h
xen/include/asm-x86/time.h